import smtplib
from email.header import Header
from email.mime.multipart import MIMEMultipart
from email.mime.text import MIMEText

# testresultfile = 'D:/LabProject/Visualization/Script/123.zip'
# attachment = MIMEText(open(testresultfile, 'rb').read(), 'base64', 'utf-8')
# attachment["Content-Type"] = 'application/octet-stream'
# attachment["Content-Disposition"] = 'attachment; filename="TestResults.zip"'
# message.attach(attachment)


def mail(content: str):
    # mail_host = "smtp.qq.com"
    sender = "764743604@qq.com"
    password = "bpozuorazgibbece"
    receivers = ['1220233389@qq.com','740632491@qq.com','369025818@qq.com','976680821@qq.com','2788330750@qq.com', '764743604@qq.com', '2216056290@qq.com']
    #邮件标题
    subject = '自动化测试报告'
    # 创建一个带附件的实例
    message = MIMEMultipart()
    message['From']=sender
    message['To'] = "张子明<1220233389@qq.com>,蒲柯汛<740632491@qq.com>,张道康<369025818@qq.com>,朱泓淼<976680821@qq.com>,顾宇轩<2788330750@qq.com>,王文博<764743604@qq.com>,陈泽西<2216056290@qq.com>;"
    message['Subject'] = Header(subject, 'utf-8')

    # 邮件正文内容
    message.attach(MIMEText(content, 'plain', 'utf-8'))

    # 连接到QQ邮箱的SMTP服务器
    smtp_server = "smtp.qq.com"
    smtp_port = 465  # QQ邮箱的SMTP端口，SSL加密
    ret=True
    try:
        smtp_obj = smtplib.SMTP_SSL(smtp_server, smtp_port)
        # 登录邮箱
        smtp_obj.login(sender, password)
        # 发送邮件
        smtp_obj.sendmail(sender, receivers, message.as_string())
        print("邮件发送成功")
    except Exception as e:
        ret = False
        print("error",e)
    return ret